#!/usr/bin/env python
# -*- coding: utf-8 -*- 
import time
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


brower = webdriver.Chrome(executable_path = r"D:/user/Downloads/chromedriver")
time.sleep(2)
brower.get('http://itsm-rpt.sf-express.com/balantflow/')

#账号
zh = brower.find_element_by_id("username")
zh.send_keys("01383317")

#密码
mm = brower.find_element_by_id("password")
mm.send_keys("liuj1a!wei")
time.sleep(8)

#登陆
dl = brower.find_element_by_css_selector(".f18.logn_lt.logn_btn.lh46")
dl.click()

#查询
#cx = brower.find_elements_by_css_selector(".menu-text")[2]
#print cx
#cx.click()
#time.sleep(2)
#单纯点击
#gdcx = brower.find_elements_by_class_name("tab-text")[1] 
#gdcx.click()

#定位到ifarme里面才能进行下一步	
#brower.switch_to.frame(brower.find_elements_by_css_selector(".iframe-item")[1])
#ss = brower.find_element_by_id("divSearch")
#ss.click()
#time.sleep(1)

#批量查询
l = sys.argv
print len(l)
print l

b = len(l)
a = 0
while a < b:
  if a < b:
    #查询
    cx = brower.find_elements_by_css_selector(".menu-text")[2]
    print cx
    cx.click()
    time.sleep(2)
	#单纯点击
    gdcx = brower.find_elements_by_class_name("tab-text")[1] 
    gdcx.click()
	#定位到ifarme里面才能进行下一步	
    brower.switch_to.frame(brower.find_elements_by_css_selector(".iframe-item")[1])
    ss = brower.find_element_by_id("divSearch")
    ss.click()
    time.sleep(1)
	#发送流水号
    lsh = brower.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/input")
    lsh.clear()
    lsh.send_keys(str(l.pop()))
    time.sleep(1)
    qd = brower.find_element_by_xpath("/html/body/div[1]/div[2]/div[2]/button[1]").click()
    time.sleep(2)
	#点击标题
    djbt = brower.find_element_by_xpath('.//*[@id="mainDiv"]/table/tbody/tr[1]/td[1]/div/a').click()
    chakan = brower.find_element_by_xpath('//*[@id="menuDiv_3683423"]/ul/li[1]/a')
    chakan.click()
    print l.pop()
    time.sleep(2)
	#点击查看
    chakan = brower.find_element_by_css_selector('#menuDiv_3685558 > ul > li:nth-child(1) > a')
    chakan.click()
	#退出iframe
    brower.switch_to_default_content()
  elif b == 1:
    break
  a += 1

   

#定位到ifarme里面才能进行下一步
#brower.switch_to_frame("iframe-item-8438a028-7d7b-4056-8722-31ad65bd81a3")
#动态定位
#brower.switch_to.frame(brower.find_elements_by_css_selector(".iframe-item")[1])
#ss = brower.find_element_by_id("divSearch")
#ss.click()
#time.sleep(1)

#定位流水号
#lsh = brower.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/input")
#lsh.send_keys("RL003674863")
#lsh.send_keys(sys.argv[1])

#time.sleep(1)
#qd = brower.find_element_by_xpath("/html/body/div[1]/div[2]/div[2]/button[1]").click()
#time.sleep(1)

#OK
#点击标题
#djbt = brower.find_element_by_xpath('.//*[@id="mainDiv"]/table/tbody/tr[1]/td[1]/div/a').click()


